package com.example.administrator.myapplication4;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

import com.example.administrator.myapplication4.adapter.Myadapter;
import com.example.administrator.myapplication4.bean.Weather;
import com.example.administrator.myapplication4.util.GetJsonDataUtil;
import com.google.gson.Gson;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private ListView weatherListview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        weatherListview = (ListView) findViewById(R.id.weather_listview);


    }

    private void initData() {
        String jsonData = new GetJsonDataUtil().getJson(MainActivity.this, "data.json");
        Log.e(TAG, "initData: " + jsonData);
        Gson gson = new Gson();
        //映射关系
        Weather weathers = gson.fromJson(jsonData, Weather.class);
        String todayTemperature = weathers.getResult().getToday().getTemperature();
        Toast.makeText(MainActivity.this, todayTemperature, Toast.LENGTH_SHORT).show();
//        String wind_sterngth = weathers.getResult().getSk().getWind_strength();
//        Toast.makeText(MainActivity.this, wind_sterngth, Toast.LENGTH_SHORT).show();
//        String humidity = weathers.getResult().getSk().getHumidity();
//        Toast.makeText(MainActivity.this, humidity, Toast.LENGTH_SHORT).show();
        List<Weather.ResultBean.FutureBean> futurebeans = weathers.getResult().getFuture();
        Log.e(TAG, "initData: " + futurebeans.get(1).getTemperature()+ "");
        weatherListview.setAdapter(new Myadapter(MainActivity.this,futurebeans));
}

    private void initEvent() {
    }

}

